package com.gnerv.battle.boot.module.base.service.impl;

import com.gnerv.battle.boot.module.base.repository.mapper.ConfigMapper;
import com.gnerv.battle.boot.module.base.model.bo.ConfigBO;
import com.gnerv.battle.boot.module.base.model.dto.ConfigDTO;
import com.gnerv.battle.boot.module.base.model.entity.Config;
import com.gnerv.battle.boot.module.base.service.ConfigService;
import com.gnerv.battle.boot.module.base.service.CurrentAccountService;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@Service
@AllArgsConstructor
public class ConfigServiceImpl implements ConfigService {

    private final ConfigMapper configMapper;
    private final CurrentAccountService currentAccountService;

    @Override
    public boolean create(@NonNull ConfigBO configBO) {
        Config config = configBO.toCreateConfig();
        config.setCreator(currentAccountService.accountUkId());
        configMapper.insert(config);
        return true;
    }

    @Override
    public boolean deleteByUkId(@NonNull String ukId) {
        configMapper.deleteByUkId(ukId);
        return true;
    }

    @Override
    public boolean updateByUkId(@NonNull ConfigBO configBO) {
        Config config = configBO.toUpdateConfig();
        configMapper.updateByUkId(config);
        return true;
    }

    @Override
    public ConfigDTO selectByUkId(@NonNull String ukId) {
        return configMapper.selectByUkId(ukId);
    }

    @Override
    public List<ConfigDTO> listByName(String name) {
        return configMapper.listByName(name);
    }

}




